Skip to content

[internal/wclayer]: fix import temp dir leak on layer extract failure#2778

Merged
anmaxvl merged 1 commit into
microsoft:mainfrom
anmaxvl:fix/wclayer-leak-import-temp-on-enospc
Jun 18, 2026
Merged

[internal/wclayer]: fix import temp dir leak on layer extract failure#2778
anmaxvl merged 1 commit into
microsoft:mainfrom
anmaxvl:fix/wclayer-leak-import-temp-on-enospc

Conversation

@anmaxvl

@anmaxvl anmaxvl commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

When layer extraction fails because the disk is full, legacyLayerWriter.reset returned early from bufWriter.Flush (ENOSPC) before closing currentFile and backupWriter. On Windows the still-open handle prevented os.RemoveAll from deleting the temporary import directory created by os.MkdirTemp("", "hcs"), which by default (if not explicitly set) resolves to C:\Windows\SystemTemp\hcs*. As a result every failed PullImage layer extract leaked an hcs* directory and compounded disk-space exhaustion that never self-healed.

Move the handle-close logic into a deferred func in reset so the file and backup handles are always released, even on the flush-error path, allowing the deferred RemoveAll in legacyLayerWriterWrapper.Close to succeed. Also clean up importPath in NewLayerWriter when newLegacyLayerWriter fails, matching NewLayerReader's exportPath handling.

Adds wclayer reset unit tests covering the flush-error and success paths.

Co-authored-by: Claude Opus 4.8

When layer extraction fails because the disk is full, legacyLayerWriter.reset
returned early from bufWriter.Flush (ENOSPC) before closing currentFile and
backupWriter. On Windows the still-open handle prevented os.RemoveAll from
deleting the temporary import directory created by os.MkdirTemp("", "hcs"),
which by default (if not explicitly set) resolves to C:\Windows\SystemTemp\hcs*.
As a result every failed PullImage layer extract leaked an hcs* directory and
compounded disk-space exhaustion that never self-healed.

Move the handle-close logic into a deferred func in reset so the file and
backup handles are always released, even on the flush-error path, allowing the
deferred RemoveAll in legacyLayerWriterWrapper.Close to succeed. Also clean up
importPath in NewLayerWriter when newLegacyLayerWriter fails, matching
NewLayerReader's exportPath handling.

Adds wclayer reset unit tests covering the flush-error and success paths.

Co-authored-by: Claude Opus 4.8
Signed-off-by: Maksim An <maksiman@microsoft.com>
@anmaxvl anmaxvl requested a review from a team as a code owner June 17, 2026 07:27
@anmaxvl anmaxvl merged commit 1f0cac0 into microsoft:main Jun 18, 2026
19 checks passed
@anmaxvl anmaxvl deleted the fix/wclayer-leak-import-temp-on-enospc branch June 18, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants